package com.yida.wy.basic.controller.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yida.common.core.exception.ServiceException;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.wy.basic.domain.request.WyInitApiRequest;
import com.yida.wy.basic.service.IWyInitApiService;

/**
 * 小区基础数据初始化（基础数据管理模块）Controller
 * 
 * @author lqq
 * @date 2022-11-15
 */
@RestController
@RequestMapping("/api")
public class WyInitApiController extends BaseController {

    @Autowired
    private IWyInitApiService apiService;

    /**
     * 拉取楼栋信息
     */
    @GetMapping("/getCommunity")
    public AjaxResult getCommunity(@Validated WyInitApiRequest request) {
        return AjaxResult.success(apiService.getCommunity(request));
    }

    /**
     * 拉取楼栋信息
     */
    @GetMapping("/getBuild")
    public AjaxResult getBuild(@Validated WyInitApiRequest request) {
        if (StringUtils.isBlank(request.getProjectCode()) && StringUtils.isBlank(request.getBuildCode())) {
            throw new ServiceException("请求参数不全");
        }
        return AjaxResult.success(apiService.getBuild(request));
    }

    /**
     * 拉取房屋信息
     */
    @GetMapping("/getHouse")
    public AjaxResult getHouse(@Validated WyInitApiRequest request) {
        return AjaxResult.success(apiService.getHouse(request));
    }

    /**
     * 拉取业主信息
     */
    @GetMapping("/getOwner")
    public AjaxResult getOwner(@Validated WyInitApiRequest request) {
        return AjaxResult.success(apiService.getOwner(request));
    }
}
